import Mock from 'mockjs'
//延时200-600毫秒请求到数据
Mock.setup({
    timeout: '200-600'
})

const Random = Mock.Random;

// 学历分布
function countUserNum() {
    const a = Mock.mock({
        success: true,
        data: {
            offlineNum:'@integer(1, 100)',
            lockNum: '@integer(1, 10)',
            totalNum:218
        }
    })
    a.data.onlineNum=a.data.totalNum-a.data.offlineNum-a.data.lockNum
    return a
}

// 接口，第一个参数url，第二个参数请求类型，第三个参数响应回调
Mock.mock(new RegExp('countUserNum'), 'get', countUserNum)

// 性别分布
function countDeviceNum() {
    const a = Mock.mock({
        success: true,
        data: {
            girlsNum: '@integer(100, 1500)',
            boysNum: '@integer(100, 2000)',
        }
    })

    return a
}

Mock.mock(new RegExp('countDeviceNum'), 'get', countDeviceNum)


// 报道数据
function sbtx() {
    const a = Mock.mock({
        success: true,
        data: {
            "list|20": [
                {
                    provinceName: "@province()",
                    cityName: '@city()',
                    countyName: "@county()",
                    createTime: "@datetime('yyyy-MM-dd HH:mm:ss')",
                    deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                    "gatewayno|+1": 10000,
                    "onlineState|1": [0, 1],

                }
            ]
        }
    })
    return a
}

Mock.mock(new RegExp('sbtx'), 'get', sbtx)



// 中间地图

function centermap() {
	const res = Mock.mock({
		code: 0,
		data: {
			"440000": 125,
			"110000": 302,
			"220000": 142,
			"230000": 50,
			"650000": 84,
			"540000": 7,
		},
		message: "ok",
		description: ""
	});
	return res;
}

Mock.mock(new RegExp('centermap'), 'get', centermap)


//身高分布数据
function alarmNum() {
    const a = Mock.mock({
        success: true,
        data: {
            dateList:['150', '160', '170', '180', '190'],
            "numList|5":[
                '@integer(0, 400)'
            ],
            "numList2|5":[
                '@integer(0, 400)'
            ]
        }
    })
    return a
}
Mock.mock(new RegExp('alarmNum'), 'get', alarmNum)

// 生日分布
function ssyj() {
    const a = Mock.mock({
        success: true,
        data: Array.from({ length: 12 }, () => [
            Mock.mock('0'),    // Lowest value (random between 0 and 20)
            Mock.mock('@integer(21, 50)'),   // Highest value (random between 21 and 50)
            Mock.mock('@integer(10, 30)')    // Average value (random between 10 and 30)
        ])
    });
    return a;
}
Mock.mock(new RegExp('ssyj'), 'get', ssyj)


//安装计划 
function installationPlan() {
    let num = RandomNumBoth(26,32);
    const a = Mock.mock({
        ["category|"+num]:["@city()"],
        ["barData|"+num]:["@integer(10, 100)"],
    })
    let lineData=[],rateData=[];
    for (let index = 0; index < num; index++) {
        let lineNum = Mock.mock('@integer(0, 100)')+a.barData[index]
        lineData.push(lineNum)
        let rate = a.barData[index] / lineNum;
        rateData.push((rate*100).toFixed(0))
    }
    a.lineData = lineData
    a.rateData = rateData
    return {
        success: true,
        data: a
    }
}
Mock.mock(new RegExp('installationPlan'), 'get', installationPlan)




//身高分布
function ranking() {
    // 生成包含 8 个随机用户的列表，每个用户对象包含身高和数量数据
    let num = Mock.mock({
        "list|8": [
            {
                height: "@integer(150,180)",  // 生成 150 到 180 之间的随机整数作为用户的身高
                quantity: "@integer(100,300)" // 生成 100 到 300 之间的随机整数作为用户的数量
            }
        ]
    }).list;

    // 返回对象格式
    let a = {
        success: true,
        data: num
    };

    return a;
}
Mock.mock(new RegExp('ranking'), 'get', ranking);

/**
 * @description: min ≤ r ≤ max  随机数
 * @param {*} Min
 * @param {*} Max
 * @return {*}
 */

function RandomNumBoth(Min,Max){
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}
/**
 * @description: 获取路径参数
 * @param {*} url
 * @return {*}
 */

function parameteUrl(url) {
    var json = {}
    if (/\?/.test(url)) {
        var urlString = url.substring(url.indexOf("?") + 1);
        var urlArray = urlString.split("&");
        for (var i = 0; i < urlArray.length; i++) {
            var urlItem = urlArray[i];
            var item = urlItem.split("=");
            console.log(item);
            json[item[0]] = item[1];
        }
        return json;
    }
    return {};
}
